<?php

use yii\db\Migration;
use yii\db\Schema;

/**
 * Class m181025_035219_CREATE_DB
 */
class m181025_035219_CREATE_DB extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->dropColumn('{{product_tour}}', 'day_date');

        $this->addColumn('{{product_tour}}', 'begin_date', Schema::TYPE_DATE. " NOT NULL COMMENT '开始日期' AFTER product_id ");

        $this->addColumn('{{product_tour}}', 'end_date', Schema::TYPE_DATE. " NOT NULL COMMENT '结束日期' AFTER begin_date ");

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

        // 团队时间
        $this->createTable('product_date', [
            "id" =>             Schema::TYPE_PK,
            "product_id" =>     Schema::TYPE_INTEGER.   "(10) NOT NULL DEFAULT '0' COMMENT '团队ID'",

            "day_date" =>     Schema::TYPE_DATE.   " NOT NULL COMMENT '日期'",

            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",

            "created_at" =>     Schema::TYPE_DATETIME. " NULL COMMENT '创建时间'",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);

        // 团队行程
        $this->createTable('product_trip', [
            "id" =>             Schema::TYPE_PK,
            "product_id" =>     Schema::TYPE_INTEGER.   "(10) NOT NULL DEFAULT '0' COMMENT '团队ID'",

            "product_date_id" =>     Schema::TYPE_INTEGER.   "(10) NOT NULL DEFAULT '0' COMMENT '团队日期ID'",

            "trip_time" =>        Schema::TYPE_TIME. " NOT NULL COMMENT '时间'",


            "supplier_id" =>     Schema::TYPE_INTEGER.  "(10)  NULL DEFAULT '0' COMMENT '供应商ID'",

            "en_content" =>        Schema::TYPE_TEXT. "  NULL COMMENT '英文行程内容'",
            "zh_content" =>        Schema::TYPE_TEXT. "  NULL COMMENT '中文行程内容'",
            

            "status" =>         Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2 禁用 '",

            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",

            "created_at" =>     Schema::TYPE_DATETIME. " NULL COMMENT '创建时间'",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);

    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        echo "m181025_035219_CREATE_DB cannot be reverted.\n";

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m181025_035219_CREATE_DB cannot be reverted.\n";

        return false;
    }
    */
}
